package gdatastructure;

import java.io.BufferedReader;       //建立图的
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;

public class AutoBuildGraph {
	public AutoBuildGraph()
	{
		
	}
	public static Graph buildTestGraphForDijk()
	{
                Random random = new Random();
		System.out.println("the graph is being made ....");
		Graph mygraph = new Graph(321270);//一共有321270个点
                int streetsize=0;
		int x1,x2,x3,x4;
		   try {
                String encoding="GBK";
                File file=new File("C:\\Users\\ASUS\\Desktop\\导师\\JavaApplication\\USA-road-d.BAY (2).txt");
                if(file.isFile()||file.exists()){ //判断文件是否存在
                    InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式
                    BufferedReader bufferedReader = new BufferedReader(read);
                    String lineTxt = null;
                    while((lineTxt = bufferedReader.readLine()) != null){
                        if(lineTxt.charAt(0)=='a'){
                            streetsize=streetsize+1; //将有多少条的街道写出来了
                            String []s=lineTxt.split("\\s+");
                                        x1=Integer.parseInt(s[1]);
					x2=Integer.parseInt(s[2]);
					x3=Integer.parseInt(s[3]);
					mygraph.connect(x1,x2,x3);
                                        x4=x3;
                        }
                        
                    }
                    mygraph.setstreetsize(streetsize);//此刻的streetsize就是街道的数量
                    read.close();
        }else{
            System.out.println("找不到指定的文件");
        }
        } catch (IOException | NumberFormatException e) {
            System.out.println("读取文件内容出错");
        }
                   //分界线 上面是2文件构图，下面是将点的坐标赋值进入图的内部。
		int y1,y2,y3; //y1为名字，y2为横坐标，y3为纵坐标
		   try {
                    String encoding="GBK";
                    File file=new File("C:\\Users\\ASUS\\Desktop\\导师\\JavaApplication\\USA-road-d.BAY.txt");
                    if(file.isFile() && file.exists()){ //判断文件是否存在
                    InputStreamReader read = new InputStreamReader(
                    new FileInputStream(file),encoding);//考虑到编码格式
                    BufferedReader bufferedReader = new BufferedReader(read);
                    String lineTxt = null;
                    while((lineTxt = bufferedReader.readLine()) != null){
                        if(lineTxt.charAt(0)=='v'){
                            String []s=lineTxt.split("\\s+");
                                        y1=Integer.parseInt(s[1]);
					y2=Integer.parseInt(s[2]);
					y3=Integer.parseInt(s[3]);
					mygraph.turnstreetin(y1,y2,y3); //将对应点的X和Y都放入了点中
                                        
                        }
                    }
                    read.close();
        }else{
            System.out.println("找不到指定的文件");
        }
        } catch (IOException | NumberFormatException e) {
            System.out.println("读取文件内容出错");
        }	
		return mygraph;		
	}
	
        	
	
}
